-- note that DifficultyList's code remains because I may bring it back.
-- don't hold your breath though.

-- todo: SPLIT THIS STUFF OUT, GOT DAMN

local iIndex = Var("GameCommand"):GetIndex();
local sName = Var("GameCommand"):GetName();

-- common stuff for everyone to love!!
local genericGainFocusCmd = cmd(finishtweening;visible,true);
local genericLoseFocusCmd = cmd(visible,false);

local t = Def.ActorFrame{
	Name="Item"..iIndex;
	GainFocusCommand=genericGainFocusCmd;
	LoseFocusCommand=genericLoseFocusCmd;

	AutoText("frutiger")..{
		Name="StyleName"..iIndex;
		Text=THEME:GetString(Var 'LoadingScreen',sName);
		InitCommand=cmd(shadowlength,1;diffuse,color("#FFFFFF");NoStroke);
		BeginCommand=function(self)
			if SSMusicInfoDefaultChoice() == sName then
				self:diffuse(color("#FFDD00"))
			end
		end;
		OnCommand=cmd(y,(SCREEN_CENTER_Y*0.8)-48);
	};
	AutoText("frutiger")..{
		Name="InfoOption"..iIndex;
		Text=THEME:GetString(Var 'LoadingScreen',sName.."Desc");
		InitCommand=cmd(shadowlength,0;zoom,0.6;diffuse,color("#000000");NoStroke);
		OnCommand=cmd(y,SCREEN_CENTER_Y*0.8);
	};
};

-- dividers
if(sName == "DifficultyList" or sName == "RadarBars") then
	t[#t+1] = Def.ActorFrame{
		Name="Dividers";
		InitCommand=cmd(diffuse,color("0,0,0,0.25"));
		OnCommand=cmd(diffusealpha,0;linear,0.2;diffusealpha,1);
		OffCommand=cmd(linear,0.2;diffusealpha,0);

		Def.Quad{
			Name="Divider1";
			InitCommand=cmd(y,10;zoomto,294,2);
		};
		Def.Quad{
			Name="Divider2";
			InitCommand=cmd(y,30;zoomto,294,2);
		};
		Def.Quad{
			Name="Divider3";
			InitCommand=cmd(y,50;zoomto,294,2);
		};
		Def.Quad{
			Name="Divider4";
			InitCommand=cmd(y,70;zoomto,294,2);
		};
	};
end;

--[[ option-specific junk ]]

-- DifficultyList (currently disabled)
if(sName == "DifficultyList") then
	t[#t+1] = Def.ActorFrame{
		Name="DifficultyListPreview";
		GainFocusCommand=genericGainFocusCmd;
		LoseFocusCommand=genericLoseFocusCmd;

		LoadActor("_cursor p1") .. {
			Name="CursorP1";
			InitCommand=cmd(x,-128);
		};

		LoadActor("_cursor p2") .. {
			Name="CursorP2";
			InitCommand=cmd(x,128;y,60);
		};

		OffFocusedCommand=function(self)
			SetUserPref("SSMusicInfo","DifficultyList");
		end;
	};

	for i, diff in pairs(Difficulty) do
		-- hack to hide edit (only show 5 difficulties at once)
		if i < 6 then
			t[#t+1] = AutoText("frutiger")..{
				Text=(i*2);
				InitCommand=cmd(x,-96;y,(i-1)*20;shadowlength,0;zoom,0.75;NoStroke);
				BeginCommand=function(self)
					self:diffuse( DifficultyColor(diff) );
				end;
			};

			for j=1,i*2 do
				t[#t+1] = LoadActor( "_ticks 7x1" )..{
					InitCommand=cmd(horizalign,left;x,-64+(j*7);y,(i-1)*20;shadowlength,0;pause);
					BeginCommand=function(self)
						self:setstate(i-1);
					end;
				};
			end;
			for j=(i*2)+1,20 do
				t[#t+1] = LoadActor( "_ticks 7x1" )..{
					InitCommand=cmd(horizalign,left;x,-64+(j*7);y,(i-1)*20;shadowlength,0;pause);
					BeginCommand=function(self)
						self:setstate(6);
					end;
				};
			end;
		end;
	end;

-- RadarBars
elseif(sName == "RadarBars") then
	t[#t+1] = Def.ActorFrame{
		Name="RadarBarsPreview";
		GainFocusCommand=genericGainFocusCmd;
		LoseFocusCommand=genericLoseFocusCmd;
		
		OffFocusedCommand=function(self)
			SetUserPref("SSMusicInfo","RadarBars");
		end;
	};

	local radarCats = { "Stream", "Voltage", "Air", "Freeze", "Chaos" };

	t[#t+1] = Def.Quad{
		Name="RB_Background";
		InitCommand=cmd(zoomto,192,96;x,28;y,40);
		OnCommand=cmd(diffuse,color("0.25,0.25,0.25,0.75"));
	};

	t[#t+1] = Def.ActorFrame{
		InitCommand=cmd(x,-63);

		AutoText("frutiger")..{
			InitCommand=cmd(y,-16;shadowlength,1;zoom,0.55;diffuse,color("#FFFFFF");settext,"0%";horizalign,left;NoStroke);
		};

		Def.Quad{
			Name="RB_0";
			InitCommand=cmd(zoomto,2,92;y,40);
			OnCommand=cmd(diffuse,color("1,1,1,0.5"));
		};
	};

	t[#t+1] = Def.ActorFrame{
		InitCommand=cmd(x,28);

		AutoText("frutiger")..{
			InitCommand=cmd(y,-16;shadowlength,1;zoom,0.55;diffuse,color("#FFFFFF");settext,"50%";NoStroke);
		};

		Def.Quad{
			Name="RB_50";
			InitCommand=cmd(zoomto,2,92;y,40);
			OnCommand=cmd(diffuse,color("1,1,1,0.5"));
		};
	};

	t[#t+1] = Def.ActorFrame{
		InitCommand=cmd(x,120);

		AutoText("frutiger")..{
			InitCommand=cmd(y,-16;shadowlength,1;zoom,0.55;diffuse,color("#FFFFFF");settext,"100%";horizalign,right;NoStroke);
		};

		Def.Quad{
			Name="RB_100";
			InitCommand=cmd(zoomto,2,92;y,40);
			OnCommand=cmd(diffuse,color("1,1,1,0.5"));
		};
	};

	for i=1,#radarCats do
		t[#t+1] = AutoText("frutiger")..{
			InitCommand=cmd(x,-80;y,(i-1)*20;shadowlength,1;zoom,0.5;diffuse,color("#FFFFFF");settext,THEME:GetString("RadarCategory",radarCats[i]);horizalign,right;NoStroke);
		};

		local r = math.random(1,3);
		local barsize = 12;
		local p;
		if r == 1 or r == 2 then
			-- P1 or P2 only
			if r == 1 then p = PLAYER_1;
			else p = PLAYER_2;
			end;

			t[#t+1] = Def.Quad{
				InitCommand=function(self)
					self:diffuse(PlayerColor(p));
					self:diffusebottomedge(PlayerMidColor(p));
					local width = math.random(64,184);
					self:x(-64);
					self:y((i-1)*20);
					self:zoomx(width);
					self:zoomy(barsize);
					self:horizalign(left);
				end;
			};
		else
			-- both
			local width = math.random(64,184);
			for s=1,2 do
				t[#t+1] = Def.Quad{
					InitCommand=function(self)
						if s == 1 then p = PLAYER_1;
						else p = PLAYER_2;
						end;

						self:diffuse(PlayerColor(p));
						self:diffusebottomedge(PlayerMidColor(p));
						self:x(-64);
						if s == 1 then self:y( ((i-1)*20)-3 );
						else self:y( ((i-1)*20)+3 );
						end;
						self:zoomx(width);
						self:zoomy(barsize/2);
						self:horizalign(left);
					end;
				};
			end;
		end;
	end;

-- PaneDisplay
elseif(sName == "PaneDisplay") then
	local paneCats = { "Steps", "Jumps", "Holds", "Mines", "Hands", "Rolls" };

	t[#t+1] = Def.ActorFrame{
		Name="PaneDisplayPreview";
		GainFocusCommand=genericGainFocusCmd;
		LoseFocusCommand=genericLoseFocusCmd;

		OffFocusedCommand=function(self)
			SetUserPref("SSMusicInfo","PaneDisplay");
		end;

		LoadActor( THEME:GetPathB("","_frame 3x3"), "_square blackinset transparent normal", 238, 80)..{
			InitCommand=cmd(y,56);
		};

		LoadActor( THEME:GetPathB("","_frame 3x1"), "_infobox header", 238 )..{
			InitCommand=cmd(diffuse,PlayerColor(PLAYER_1);y,-5);
		};

		AutoText("frutiger")..{
			InitCommand=cmd(shadowlength,1;zoom,0.55;y,-5;settext,"P1 Information";NoStroke);
		};
	};

	for i=1,#paneCats do
		t[#t+1] = Def.ActorFrame{
			InitCommand=cmd(x,-64;y,(i)*16);

			AutoText("frutiger")..{
				Text=THEME:GetString("PaneDisplay",paneCats[i]);
				InitCommand=cmd(shadowlength,1;horizalign,right;zoom,0.55;NoStroke);
			};

			AutoText("frutiger")..{
				InitCommand=cmd(x,8;shadowlength,1;horizalign,left;zoom,0.55;playcommand,"Set";NoStroke);
				SetCommand=cmd(settext,math.random(1,500));
			};
		};
	end;
end;

return t;